#include <iostream>
#include <fstream>
#include <cstdlib>

#include "commondata.hpp"

#include "arena.hpp"
#include "datatable.hpp"
#include "dblmdb.hpp"
#include "dbmemory.hpp"
#include "dbsqlite.hpp"
#include "logger.h"
#include "player.hpp"
#include "shipai.hpp"
#include "trophy.hpp"

#include <time.h>
#include <spdlog/spdlog.h>

int main(int argc, char ** argv) {
	DataTable::init();
	std::string inputName = "test.txt";
	auto log = Logger::get("MAIN");

	if( argc > 1 ){
		log->info("Use '{}' instead of '{}'", argv[1], inputName );
		inputName = argv[1];
	}

	PlayerData data;
	if( Player::importData(inputName.c_str(), &data) ){
		DBMemory testdb(sizeof(PathData));
		clock_t t1, t2;
		
		std::chrono::duration<float> dur;
		t1 = clock(); auto start = std::chrono::steady_clock::now();
// 		Player::createGraph(&testdb, data);
		t2 = clock(); auto stop = std::chrono::steady_clock::now();
		dur = stop - start;
		log->info("ST cpu time: {} ms, real time {}", 1000*(t2-t1)/CLOCKS_PER_SEC, dur.count());

		t1 = clock(); start = std::chrono::steady_clock::now();
		Player::createGraphMT(&testdb, data);
		t2 = clock(); stop = std::chrono::steady_clock::now();
		dur = stop - start;
		log->info("MT cpu time: {} ms, real time {}", 1000*(t2-t1)/CLOCKS_PER_SEC, dur.count());

		Player::finalizePath(&testdb, data);
	} else {
		log->error("can not load player data from '{}'", inputName);
	}

	return 0;
}
